package com.yy.controller;


import cn.hutool.core.collection.CollUtil;
import com.github.pagehelper.PageInfo;
import com.yy.domain.*;
import com.yy.dto.*;
import com.yy.service.*;
import com.yy.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 姚欣宏
 * @since 2023-07-06
 */
@Slf4j
@Api(tags = "任务相关接口")
@RestController
@RequestMapping("/api/v1/appointmentTasks")
public class AppointmentTasksController {

    private final AppointmentTasksService appointmentTasksService;

    public AppointmentTasksController(AppointmentTasksService appointmentTasksService) {
        this.appointmentTasksService = appointmentTasksService;
    }

    @ApiOperation("创建任务")
    @PostMapping("/insert/appointmentTasks")
    public ResponseResult<Integer> appointmentTasks(@RequestBody AppointmentTasksVO appointmentTasksVO) {
        Integer id = appointmentTasksService.appointmentTasks(appointmentTasksVO);
        return new ResponseResult<>(200, "保存成功", id);
    }


    @ApiOperation("获取任务详情")
    @GetMapping("/getTasks")
    public ResponseResult<AppointmentTasksDO> getTasks(@RequestParam Integer id) {
        AppointmentTasksDO appointmentTasksDO = appointmentTasksService.getById(id);
        return new ResponseResult<>(200, "请求成功", appointmentTasksDO);
    }

    @ApiOperation("复制")
    @GetMapping("/copy")
    public ResponseResult<Void> copy(@RequestParam Integer id) {
        appointmentTasksService.copy(id);
        return new ResponseResult<>(200, "请求成功");
    }

    @ApiOperation("任务列表")
    @PostMapping("/select/appointmentTasks")
    public ResponseResult<PageInfo<AppointmentTasksDO>> selectAppointmentTsks(@RequestBody AppointmentTasksPageVO appointmentTasksPageVO) {
        PageInfo<AppointmentTasksDO> pageInfo = appointmentTasksService.selectAppointmentTsks(appointmentTasksPageVO);
        return new ResponseResult<>(200, "请求成功", pageInfo);
    }

    @ApiOperation("配置任务")
    @PostMapping("/configuration/appointmentTasks")
    public ResponseResult<Integer> configurationAppointmentTasks(@RequestBody AppointmentTasksVO appointmentTasksVO) {
        Integer id = appointmentTasksService.configurationAppointmentTasks(appointmentTasksVO);
        return new ResponseResult<>(200, "请求成功", id);
    }

    @ApiOperation("就诊卡列表")
    @GetMapping("/cardlist")
    public ResponseResult<List<UserCardListDTO>> cardlist(@RequestParam Integer id) {
        List<UserCardListDTO> cardListDTOS = appointmentTasksService.cardlist(id);
        return new ResponseResult<>(200, "请求成功", cardListDTOS);
    }

    @ApiOperation("华西园区科室列表")
    @GetMapping("/selFirstDept")
    public ResponseResult<List<DeptDTO>> selFirstDept(@RequestParam Integer id) {
        List<DeptDTO> deptDTOS = appointmentTasksService.selFirstDept(id);
        return new ResponseResult<>(200, "请求成功", deptDTOS);
    }

    @ApiOperation("按更多条件选择医生列表")
    @GetMapping("/selDoctorListByMoreTerm")
    public ResponseResult<List<DoctorDTO>> selDoctorListByMoreTerm(@RequestParam Integer id, @RequestParam String deptCategoryCode) {
        List<DoctorDTO> doctorDTOS = appointmentTasksService.selDoctorListByMoreTerm(id, deptCategoryCode);
        return new ResponseResult<>(200, "请求成功", doctorDTOS);
    }


    @ApiOperation("查询医生一周的排班")
    @PostMapping("/selWeekScheduleTwo")
    public ResponseResult<List<ScheduleDTO>> selWeekScheduleTwo(@RequestBody ScheduleRequestVO scheduleRequestVO) {
        List<ScheduleDTO> scheduleDTOS = appointmentTasksService.selWeekScheduleTwo(scheduleRequestVO);
        if (CollUtil.isNotEmpty(scheduleDTOS)) {
            return new ResponseResult<>(200, "请求成功", scheduleDTOS);
        } else {
            return new ResponseResult<>(500, "请求成功");
        }

    }

    @ApiOperation("获取验证码")
    @GetMapping("/getImageCode")
    public ResponseResult<ImageDataDO> getImageCode(@RequestParam Integer id) {
        ImageDataDO imageDataDO = appointmentTasksService.getImageCode(id);
        if (!Objects.isNull(imageDataDO)) {
            return new ResponseResult<>(200, "请求成功", imageDataDO);
        } else {
            return new ResponseResult<>(500, "请求成功");
        }
    }

    @ApiOperation("校验token是否有效")
    @GetMapping("/checkToken")
    public ResponseResult<String> checkToken(@RequestParam Integer id) {
        String checkToken = appointmentTasksService.checkToken(id);
        return new ResponseResult<>(200, "请求成功", checkToken);
    }


    @ApiOperation("手动提交预约")
    @GetMapping("/sureAppointment")
    public ResponseResult<String> sureAppointment(@RequestParam Integer id) {
        return new ResponseResult<>(200, "请求成功", appointmentTasksService.sureAppointment(id));
    }

    @ApiOperation("预约记录")
    @GetMapping("/selAppointmentRecord")
    public ResponseResult<List<ContentDTO>> selAppointmentRecord(@RequestParam Integer id) {
        List<ContentDTO> contentDTOS = appointmentTasksService.selAppointmentRecord(id);
        return new ResponseResult<>(200, "请求成功", contentDTOS);
    }

    @ApiOperation("取消预约")
    @PostMapping("/appointmentCancelOrBack")
    public ResponseResult<Void> appointmentCancelOrBack(@RequestBody BackDTO backDTO) {
        appointmentTasksService.appointmentCancelOrBack(backDTO);
        return new ResponseResult<>(200, "请求成功");
    }

    @ApiOperation("去支付")
    @PostMapping("/appointmentToPay")
    public ResponseResult<String> appointmentToPay(@RequestBody BackDTO backDTO) {
        String toPayDTO = appointmentTasksService.appointmentToPay(backDTO);
        return new ResponseResult<>(200, "请求成功",toPayDTO);
    }

}

